package sanrenxing.dayEnd.backRepertoryTotal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sanrenxing.dayEnd.backRepertoryTotal.domain.SecuritiesStock;
import sanrenxing.dayEnd.backRepertoryTotal.domain.SecuritiesStockTwo;
import sanrenxing.dayEnd.backRepertoryTotal.service.SecuritiesStockBiz;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能：证券库存表的控制器类
 * 作者：赵思睿
 * 日期：2021/3/12 0012-15:12
 * 版本：1.0
 */
@RestController
@RequestMapping("/secStockcrud")
public class SecuritiesStockController {
    @Autowired
    private SecuritiesStockBiz secStockBiz;

    /**
     * 多条件分页查询
     * @param page 页数
     * @param limit 每页行数
     * @param secStock 证券库存对象
     * @return 证券库存对象集合
     */
    @GetMapping("/secStock")
    public Map<String,Object> selectSecStock(int page, int limit, SecuritiesStock secStock){
        //执行多条件分页查询
        List<SecuritiesStockTwo> secStockList=secStockBiz.selectAll(secStock,limit,(page-1)*limit);
        //多条件查询表中总记录数
        int totalRows=secStockBiz.count(secStock);

        //定义映射对象集合
        Map<String,Object> mapData=new HashMap<String, Object>();
        mapData.put("code",0);
        mapData.put("msg","");
        mapData.put("count",totalRows);
        mapData.put("data",secStockList);

        //返回映射对象集合
        return mapData;
    }

    /**
     * 添加证券库存信息
     * @param secStock 证券库存对象
     * @return 1：添加成功；0：添加失败
     */
    @PostMapping("/secStock")
    public String add(@RequestBody SecuritiesStock secStock){
        return secStockBiz.add(secStock)>0?"add success":"add failure";
    }

    /**
     * 根据证券库存编号删除信息
     * @param secId 证券库存编号
     * @return 1：删除成功；0：删除失败
     */
    @DeleteMapping("/secStock/{secId}")
    public String delete(@PathVariable String secId){
        return secStockBiz.delete(secId)>0?"delete success":"delete failure";
    }

}
